package com.example.administrator.maizuofilm.mine;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.maizuofilm.R;
import com.example.administrator.maizuofilm.cinema.view.UrlUtils;
import com.example.administrator.maizuofilm.mine.other.Feedback;
import com.example.administrator.maizuofilm.mine.other.HotApp;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.HttpHandler;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

public class Setting extends Activity {

    private static final String PHONE_NUMBER = "4001808400";
    @InjectView(R.id.rl_bindmob)
    LinearLayout rlBindmob;
    @InjectView(R.id.rl_setpaycode)
    LinearLayout rlSetpaycode;
    @InjectView(R.id.rl_deletecash)
    LinearLayout rlDeletecash;
    @InjectView(R.id.rl_feedback)
    LinearLayout rlFeedback;
    @InjectView(R.id.rl_score)
    LinearLayout rlScore;
    @InjectView(R.id.rl_checkversion)
    LinearLayout rlCheckversion;
    @InjectView(R.id.rl_call)
    LinearLayout rlCall;
    @InjectView(R.id.rl_recommend)
    LinearLayout rlRecommend;

    @InjectView(R.id.cardvoucher_switch)
    ImageView cardvoucherSwitch;
    @InjectView(R.id.push_switch)
    ImageView pushSwitch;
    @InjectView(R.id.setting_back)
    ImageView settingBack;
    @InjectView(R.id.tv_checkversion)
    TextView tvCheckversion;


    private HttpUtils httpUtils;
    private HttpHandler<String> handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_more);
        ButterKnife.inject(this);
        httpUtils = new HttpUtils();
    }


    @OnClick({R.id.setting_back, R.id.rl_bindmob, R.id.rl_setpaycode, R.id.rl_deletecash, R.id.cardvoucher_switch, R.id.push_switch, R.id.rl_feedback, R.id.rl_score, R.id.rl_checkversion, R.id.rl_call, R.id.rl_recommend})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.setting_back:
                Setting.this.finish();
                break;
            case R.id.rl_bindmob:

                break;
            case R.id.rl_setpaycode:
                break;
            case R.id.cardvoucher_switch:
                if (Variable.DDADD) {
                    cardvoucherSwitch.setImageResource(R.drawable.bg_swtich);
                    Variable.DDADD = false;
                    Toast.makeText(Setting.this, "取消默认添加订单到支付宝电子券", Toast.LENGTH_SHORT).show();
                } else {
                    cardvoucherSwitch.setImageResource(R.drawable.bg_swtich_f);
                    Variable.DDADD = true;
                    Toast.makeText(Setting.this, "支付宝支付后订单将默认添加到支付宝电子券", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.push_switch:
                if (Variable.JSMSG) {
                    pushSwitch.setImageResource(R.drawable.bg_swtich);
                    Variable.JSMSG = false;
                    Toast.makeText(Setting.this, "关闭接收推送消息", Toast.LENGTH_SHORT).show();
                } else {
                    pushSwitch.setImageResource(R.drawable.bg_swtich_f);
                    Variable.JSMSG = true;
                    Toast.makeText(Setting.this, "开启接收推送消息", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.rl_deletecash:
                break;
            case R.id.rl_feedback:
                //我的反馈
                Intent intent = new Intent(Setting.this, Feedback.class);
                startActivity(intent);
                break;
            case R.id.rl_score:
                //给我们评分
                try {
                    Uri uri = Uri.parse("market://details?id=com.hyx.maizuo.main");
                    Intent intent3 = new Intent(Intent.ACTION_VIEW, uri);
                    intent3.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent3);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(Setting.this, "Couldn't launch the market !", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.rl_checkversion:
                //版本更新
                update();
                break;
            case R.id.rl_call:
                //客服电话
                Intent intent2 = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + PHONE_NUMBER));
                startActivity(intent2);
                break;
            case R.id.rl_recommend:
                Intent intenth = new Intent(Setting.this, HotApp.class);
                startActivity(intenth);
                break;

        }
    }

    //当点击版本更新的时候，所做的操作
    private void update() {
        tvCheckversion.setText("版本检测中…");
//        handler = httpUtils.send(HttpRequest.HttpMethod.GET, UrlUtils.NewVersion, new RequestCallBack<String>() {
//            //访问网络服务器接口失败时回调的方法
//            @Override
//            public void onFailure(HttpException exception, String msg) {
//                exception.printStackTrace();
//            }
//
//            //访问网络服务器接口成功时回调的方法
//            public void onSuccess(ResponseInfo<String> responseInfo) {

                Toast.makeText(Setting.this, "当前版本是最新版本", Toast.LENGTH_SHORT).show();
                tvCheckversion.setText("检查更新");
//            }
//        });
    }


}
